package handler

import (
	"car-trade-mgr/model"
	"github.com/gin-gonic/gin"
	"strconv"
)

func Role1AddNode1(c *gin.Context) {
	rid, _ := strconv.Atoi(c.PostForm("rid"))
	nid, _ := strconv.Atoi(c.PostForm("nid"))
	data := model.RN1{
		Rid: rid,
		Nid: nid,
	}
	err := model.DB.Create(&data).Debug().Error
	if err != nil {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "分配失败",
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "分配成功",
	})
	return
}
func User1Role1List(c *gin.Context) {
	Uid := c.Query("uid")
	var Role []model.Role
	/*
		SELECT
		*
		FROM
		role1
		LEFT JOIN ur1 ON ur1.rid=role1.id
		WHERE ur1.uid=1
	*/
	model.DB.Table("role1").
		Joins("LEFT JOIN ur1 ON ur1.rid=role1.id").
		Where("ur1.uid=?", Uid).Find(&Role).Debug()
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "列表展示成功",
		"data": Role,
	})
	return
}
func Role1Node1List(c *gin.Context) {
	Rid := c.Query("rid")
	var node []model.Node1
	/*
		SELECT
		*
		FROM
		node1
		LEFT JOIN rn1 ON rn1.nid=node1.id
		WHERE rn1.rid=1
	*/
	model.DB.Table("node1").
		Joins("LEFT JOIN rn1 ON rn1.nid=node1.id").
		Where("rn1.rid=?", Rid).Find(&node).Debug()
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "列表展示成功",
		"data": node,
	})
	return
}
